<?php
require_once '../scripts/config.php';
require_once '../scripts/functions.php';

$query='
    Select username
    From   `'.$config['mysql']['database'].'`.`Users`
    Where   session = "'.$_GET['sessionId'].'"
    And     username = "'.$_GET['user'].'"
    And     server = "'.$_GET['serverId'].'";
';

$resource = runQuery($query);

if(mysql_num_rows($resource) == 1){
    echo "OK";
} else {
    $query='
          Update  	`'.$config['mysql']['database'].'`.`Users`
          Set      	server = "'.$_GET['serverId'].'"
          Where	        username = "'.$_GET['user'].'"
          And       session = "'.$_GET['sessionId'].'"
        ';
        
    $resource = runQuery($query);
    
    if(mysql_affected_rows($config['mysql']['link']) == 1){
        echo "OK";
    } else {
        echo "Bad login";
    }
}
?>